import request, { ApiResponse, PageResponse } from './http';

import { BASE_URL } from '@/config'; // 导入基础 URL

/**
 * 课程签到
 * @param classId 课程id
 * @param teacherId 教师id
 * @param studentIds 学生id
 * @returns 签到结果
 */
interface ClassClockInReq {
  classId: number
  teacherId: number
  studentIds: number[]
}
/**
 * 下课打卡请求参数
 */
interface ClassClockOutReq {
  classId: number
}

/**
 * 授课记录查询参数
 */
interface ClassClockInRecordVo {
  teacherId?: number
  courseType?: string
  pageNo?: number
  pageSize?: number
}

/**
 * 授课记录响应数据
 */
interface LectureRecord {
  id: number
  courseName: string
  className: string
  teacherName: string
  startTime: string
  endTime: string
  consumeTime: number
  chargeableTime: number
  // 可根据实际返回数据添加更多字段
}



/**
 * 获取课程类型
 * @returns  课程类型
 */
export const getCourseOptions = async (): Promise<ApiResponse<object>> => {
  try {
    const res = await request({
      url: '/common/courseType',
      method: 'GET'
    });
    return res as ApiResponse<object>;
  } catch (err) {
    throw err;
  }
};


/**
 * 获取能打卡的记录
 * @returns 能打卡的记录
 */
export const getTeacherClassTree = async (teacherId: number, courseType: string): Promise<ApiResponse<object>> => {
  try {
    const res = await request({
      url: '/wx/qf/class/teacherClassTree',
      method: 'GET',
      params: {
        teacherId: teacherId,
        courseType: courseType
      }
    });
    return res as ApiResponse<object>;
  } catch (err) {
    throw err;
  }
};

/**
 * 上课打卡
 * @returns  
 */
export const clockIn = async (classClockInReq: ClassClockInReq): Promise<ApiResponse<object>> => {
  try {
    const res = await request({
      url: '/wx/qf/class/clockIn',
      method: 'POST',
      data: classClockInReq
    });
    return res as ApiResponse<object>;
  } catch (err) {
    throw err;
  }
};


/**
 * 获取未打下课卡的记录
 * @param teacherId 教师ID
 * @returns 未打下课卡的记录列表
 */
export const getClockOutListByTeacherId = async (teacherId: number): Promise<PageResponse<object>> => {
  try {
    const res = await request({
      url: `/wx/qf/class/clockOutList/${teacherId}`,  // 使用模板字符串替换路径变量
      method: 'GET'
    });
    return res as PageResponse<object>;
  } catch (err) {
    throw err;
  }
};



/**
 * 获取授课记录
 * @param params 查询参数
 * @returns 获取授课记录
 */
export const getLectureList = async (params: ClassClockInRecordVo): Promise<PageResponse<LectureRecord>> => {
  try {
    const res = await request({
      url: '/wx/qf/class/lecture/list',
      method: 'GET',
      params: params
    });
    return res as PageResponse<LectureRecord>;
  } catch (err) {
    throw err;
  }
};


/**
 * 获取学生上课记录
 * @param params 查询参数
 * @returns 获取上课记录
 */
export const getClassList = async (params: ClassClockInRecordVo): Promise<PageResponse<LectureRecord>> => {
  try {
    const res = await request({
      url: '/class/page',
      method: 'GET',
      params: params
    });
    return res as PageResponse<LectureRecord>;
  } catch (err) {
    throw err;
  }
};




/**
 * 下课打卡
 * @param classClockOutReq 下课打卡请求参数
 * @returns 打卡结果
 */
export const clockOut = async (classClockOutReq: ClassClockOutReq): Promise<ApiResponse<object>> => {
  try {
    const res = await request({
      url: '/wx/qf/class/clockOut',
      method: 'POST',
      data: classClockOutReq
    });
    return res as ApiResponse<object>;
  } catch (err) {
    throw err;
  }
};




